import 'package:convergence_media/di/di.dart';
import 'package:convergence_media/features/api/apis/circle_csavs_api.dart';
import 'package:convergence_media/features/app/repository/app_config_repository.dart';
import 'package:convergence_media/features/config/logger/logger.dart';
import 'package:convergence_media/features/user/repositories/token_repository.dart';
import 'package:convergence_media/interceptors/circle_interceptor.dart';
import 'package:convergence_media/interceptors/navadmin_interceptor.dart';
import 'package:convergence_media/interceptors/response_interceptor.dart';
import 'package:convergence_media/navigator/app_router.dart';
import 'package:dio/dio.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

// call on [App]
void interceptorsInit(WidgetRef ref) {
  // 配置导航 dio 拦截器
  final navadminDio = ref.watch(navadminDioProvider);
  final navadminInterceptor = NavadminInterceptor(
    appRouter: ref.watch(appRouterProvider),
    appConfigRepository: ref.watch(appConfigRepositoryProvider),
    tokenRepository: ref.watch(tokenRepositoryProvider),
  );
  final responseInterceptor = ResponseInterceptor();
  navadminDio.interceptors.addAll([
    // navadminInterceptor,
    // responseInterceptor,
    LogInterceptor(logPrint: logger.t),
  ]);

  // 配置圈子 dio 拦截器
  final circleDio = ref.watch(circleDioProvider);
  // 按顺序添加拦截器
  final circleIntercepter = CircleInterceptor(
    appConfigRepository: ref.watch(appConfigRepositoryProvider),
    circleDio: circleDio,
    tokenRepository: ref.watch(tokenRepositoryProvider),
    circleCsavsApi: ref.watch(circleCsavsApiProvider),
  );
  circleDio.interceptors.addAll([
    // navadminInterceptor,
    // circleIntercepter,
    // responseInterceptor,
    LogInterceptor(logPrint: logger.t),
  ]);
}
